package com.example.canalclientsync.config;

import com.example.canalclientsync.script.DirSync;
import com.example.canalclientsync.script.VirtualModelSync;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author chen.cr
 * @since 2023/9/12
 */
@Component
public class StartUpSyncData implements ApplicationRunner {

    private static final Logger log = LoggerFactory.getLogger(StartUpSyncData.class);

    @Resource
    private VirtualModelSync virtualModelSync;
    @Resource
    private DirSync dirSync;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("》》》初始化数据同步..");

        // 同步模型
        long start1 = System.currentTimeMillis();
        virtualModelSync.syncData();
        long end1 = System.currentTimeMillis();
        log.info("模型数据同步耗时：{}秒", (end1 - start1) / 1000);

        // 同步文件夹
        long start2 = System.currentTimeMillis();
        dirSync.syncData();
        long end2 = System.currentTimeMillis();
        log.info("文件夹数据同步耗时：{}秒", (end2 - start2) / 1000);

        log.info("总耗时：{}秒", (end2 - start1) / 1000);
        log.info("《《《初始化数据同步完成！！");

    }

}



